<?php

class Ecard_AdminFontController extends Core_Controller_Action_Admin 
{
    public function indexAction() {
		
        $this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')
      		->getNavigation('ecard_admin_main', array(), 'ecard_admin_main_font');
		
//      $this->view->formFilter = $formFilter = new Webmix_Form_Admin_Company_Filter();
	    $page = $this->_getParam('page', 1);

	    $table = Engine_Api::_()->getDbtable('fonts', 'ecard');
	    $select = $table->select();

    
        // Make paginator
        $this->view->paginator = $paginator = Zend_Paginator::factory($select);
        $paginator->setItemCountPerPage(150);
        $this->view->paginator = $paginator->setCurrentPageNumber( $page );

  }
    

    public function approveAction()
  {
    $id = $this->_getParam('font', null);
    $approve = $this->_getParam('approve', 1);
    $this->view->ecard = $ecard = Engine_Api::_()->getItem('ecard_font', $id);
    $this->view->form = $form = new Ecard_Form_Admin_Font_Approve();
    $viewer = Engine_Api::_()->user()->getViewer();
    if(!$approve) $form->setTitle('Disapprove Font')
    					->setDescription('Are you sure you want to disapprove this font?');
    // deleting user
    //$form->user_id->setValue($id);

    if( $this->getRequest()->isPost() ) {
      $db = Engine_Api::_()->getDbtable('fonts', 'ecard')->getAdapter();
      $db->beginTransaction();

      try {
        $ecard->approve = $approve;
        $ecard->save();
        
        $db->commit();
      } catch( Exception $e ) {
        $db->rollBack();
        throw $e;
      }
      
      return $this->_forward('success', 'utility', 'core', array(
        'smoothboxClose' => true,
        'parentRefresh' => true,
        'format'=> 'smoothbox',
        'messages' => array('This font has been successfully changed.')
      ));
    }
  }
  
}
